package edu.sctu.practice.class02.hujie.online_classes_practice;

/**
 * Created by user14 on 2015/9/25.
 */
//类
public class Dog {
    //属性
    int age;
    int weight;
    String color;
    String kind;

    //方法
    public int eat() {
        System.out.println("能吃，还特别能吃，除了吃就不会其他的了。");

        return 0;
    }

    //无参的构造方法
    public Dog() {
        System.out.println("这是无参的构造方法");
    }

    public Dog(int newAge, int newWeight, String newColor, String newKind) {
        if (newAge < 2) {
            System.out.println("你的狗狗年龄小于2岁 自动赋值5岁");
            newAge = 4;
        } else {
            newAge = age;
        }
        age = newAge;
        weight = newWeight;
        color = newColor;
        kind = newKind;
        System.out.println("这是有参的构造方法");
        System.out.println();
    }

    public static void main(String[] args) {
        //实例化一只叫hua的狗
        Dog hua = new Dog();
        hua.age = 5;
        hua.weight = 20;
        hua.color = "black";
        hua.kind = "husky";
        hua.eat();
        System.out.println("夏磊的年龄是：" + hua.age + "\n" + "夏磊的种类是：" + hua.kind + "\n"
                + "夏磊的体重为：" + hua.weight + "\n" + "夏磊的颜色是：" + hua.color + "\n"
                + "夏磊能干什么？" + hua.eat() + "\n");
        //实例化一只叫夏磊的狗狗
        Dog xialei = new Dog();
        xialei.age = 1;
        xialei.weight = 10;
        xialei.color = "red";
        xialei.kind = "husky";
        hua.eat();
        System.out.println("夏磊的年龄是：" + xialei.age + "\n" + "夏磊的种类是：" + xialei.kind + "\n"
                + "夏磊的体重为：" + xialei.weight + "\n" + "夏磊的颜色是：" + xialei.color + "\n"
                + "夏磊能干什么？" + xialei.eat() + "\n");
    }
}



